package com.bw.net

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

private val client by lazy {
    OkHttpClient.Builder()
        .connectTimeout(30,TimeUnit.SECONDS)
        .readTimeout(30,TimeUnit.SECONDS)
        .writeTimeout(30,TimeUnit.SECONDS)
        .addInterceptor {
            it.proceed(it.request().newBuilder().addHeader(
                Const.TOKEN,SPUtils.getInstance().getString(
                    Const.TOKEN
                )).build())
        }
        .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
        .build()
}
val retrofit by lazy {
    Retrofit.Builder()
        .baseUrl(Const.BASE_RUL)
        .client(client)
        .addConverterFactory(GsonConverterFactory.create())
        .build()
}


inline fun <reified T> getService() = retrofit.create(T::class.java)